<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * 发送curl请求
 */
function httpRequest($url, $postData=[],$header=["Content-Type: application/json"])
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if(!empty($postData)){
        // 设置POST请求的选项
        curl_setopt($ch, CURLOPT_POST, true);
        // 设置POST请求传递的数据
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    }
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    // 设置请求头信息
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result,true);
}

/**
 * 获取两个日期中间所有日期
 * @param $startdate 开始时间
 * @param $enddate 结束时间
*/
function getDateFromRange($start_day, $end_day)
{
    if($start_day == $end_day){
        return [
            $start_day
        ];
    }
    $day_start = strtotime($start_day);
    $day_end = strtotime($end_day);
    $days =[];
    for($i=$day_start;$i<=$day_end;$i=$i +86400) {
        $temp_day=date('Y-m-d',$i);
        array_push($days,$temp_day);
    }
    return $days;
}

